package com.xm_jd.controller.goods;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.TianDao;
import com.xm_jd.model.entitys.car;
import com.xm_jd.model.entitys.user;
import com.xm_jd.utils.BaseServlet;

/**购物车的数量与总价
 * Servlet implementation class CartListServlet
 */
@WebServlet("/cartlist")
public class CartListServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CartListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				//��new��dao
				TianDao ad=new TianDao();
				user aa=(user) request.getSession().getAttribute("users");
				//�ѹ��ﳵ�������  �����ѯ���еķ���
				List<car> carlist=ad.getCartList(aa.getUser_id());
				
				List<car> xuanli=ad.getxuan(aa.getUser_id());
				double zong=0;
				int numshu=0;
				for (car o : xuanli) {
					zong+=o.getCar_gounum()*o.getShoop_price().doubleValue();
					numshu+=o.getCar_gounum();
				}
				//�����ϴ��������
				request.getSession().setAttribute("carlist", carlist);
				request.getSession().setAttribute("zong", zong);
				request.getSession().setAttribute("numshu", numshu);
				//�ض��򵽹��ﳵҳ��
				//response.sendRedirect("jsps/shoppcar.jsp");
				this.forward("shoppcar");
				//request.getRequestDispatcher("jsps/shoppcar.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
